﻿using MyManager.Business;
using MyManager.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace MyManager.WindowsClient
{
    public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Category sampCat = new Category();
            sampCat.Id = "111";
            sampCat.Name = "category 1";

            Category sampCat2 = new Category();
            sampCat2.Id = "2";
            sampCat2.Name = "category 2";

            CategoryCollection catCol = new CategoryCollection();
            catCol.Add(sampCat);
            catCol.Add(sampCat2);


            MyManager.Business.Task tempTask = new Business.Task();
            tempTask.Id = "1";
            tempTask.Title = "title 1";
            tempTask.CategoryIds = catCol.GetCategoryIds();

            MyManager.Business.Task tempTask2 = new Business.Task();
            tempTask2.Id = "1";
            tempTask2.Title = "title 1";
            tempTask2.CategoryIds= catCol.GetCategoryIds();

            TaskCollection taskCol = new TaskCollection();
            taskCol.Add(tempTask);
            taskCol.Add(tempTask2);

            XmlSerializer xmlSer = new XmlSerializer(taskCol.GetType());

            System.IO.FileStream fs = new System.IO.FileStream(@"D:\test\testfile1.xml", System.IO.FileMode.Create);
            xmlSer.Serialize(fs, taskCol);            
            

        }

        private void TestForm_Load(object sender, EventArgs e)
        {
            ICategoryDataManager categoryDataManager = new CategoryXMLDataManager(); ;
            CategoryManager manager = new CategoryManager(categoryDataManager);

            lstCategories.DataSource = manager.GetAllCategories();
            lstCategories.ValueMember = "Id";
            lstCategories.DisplayMember = "Name";
        }

        private void btnCreateTask_Click(object sender, EventArgs e)
        {
            Business.Task task = new Business.Task();

            task.Title = txtTitle.Text;
            task.Description = txtDescription.Text;
            task.CreatedDate = DateTime.Now;
            task.StartDate = dtpStartDate.Value;
            task.DueDate = dtpDueDate.Value;
            task.Status = Business.TaskStatus.Open;
            MessageBox.Show(lstCategories.SelectedItem.ToString());
            task.CategoryIds.AddRange(lstCategories.SelectedItems.);
            ITaskDataManager taskDataManager= new TaskXMLDataManager();
            TaskManager manager = new TaskManager(taskDataManager, DateTime.Now);

            MessageBox.Show(manager.Create(task)+ "");

        }

        private void btnCreateCategory_Click(object sender, EventArgs e)
        {
            Category category = new Category();
            category.Name = txtCategoryName.Text;
            category.Description = "";
            category.ParentCategoryId = null;
            ICategoryDataManager categoryDataManager = new CategoryXMLDataManager(); ;
            CategoryManager manager = new CategoryManager(categoryDataManager);
            MessageBox.Show(manager.Create(category) + "");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ITaskDataManager taskDataManager = new TaskXMLDataManager();
            TaskManager manager = new TaskManager(taskDataManager, DateTime.Now);

            MyManager.Business.Task task = manager.GetTaskById(txtTaskId.Text);

            MessageBox.Show(task.Title);

        }

        private void lstCategories_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
